package com.sansui.admin.core.ctrl;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sansui.admin.common.constant.Action;
import com.sansui.admin.common.ctrl.BaseCtrl;
import com.sansui.admin.core.groups.DictAdd;
import com.sansui.admin.core.groups.DictUpdate;
import com.sansui.admin.core.model.Dict;
import com.sansui.admin.core.model.DictPage;
import com.sansui.admin.core.service.DictService;

@RestController
@RequestMapping("/system/dict")
public class DictCtrl extends BaseCtrl {
	@Autowired
	private DictService dictService;

	@RequiresPermissions(_DICT_ROUTE + Action._LIST)
	@RequestMapping(value = Action._LIST)
	public Object list(DictPage dict) {
		return dictService.findTByPage(dict);
	}

	@RequiresPermissions(_DICT_ROUTE + Action._ADD)
	@RequestMapping(value = Action._ADD)
	public Object add(@Validated({ DictAdd.class }) Dict dict, BindingResult bindingResult) {
		return dictService.insertDict(dict);
	}

	@RequiresPermissions(_DICT_ROUTE + Action._UPDATE)
	@RequestMapping(value = Action._UPDATE)
	public Object update(@Validated({ DictUpdate.class }) Dict dict, BindingResult bindingResult) {
		return dictService.updateByPrimaryKeyDict(dict);
	}

	@RequiresPermissions(_DICT_ROUTE + Action._DELETE)
	@RequestMapping(value = Action._DELETE)
	public Object delete(String[] id) {
		return dictService.deleteByPrimaryKeyDict(id);
	}

	@RequestMapping(value = "/findDictByDict")
	public Object findDictByDict(Dict dict) {
		return dictService.findTByT(dict);
	}

	@RequestMapping(value = Action._SPRIMARY)
	public Object selectByPrimaryKey(String id) {
		return dictService.selectByPrimaryKey(id);
	}

}
